(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function(){
		initSmPages();
		window.onresize = function () {
			initSmPages();
		};
		initStudent();
		pagebtns();
	});
	function initStudent(){
		var userkey = $("#user-name",parent.document).attr("key");
		var usercode = $("#user-name",parent.document).attr("code");
		var data = {
				cmd:"getStudentByUserCode",
				model:"user",
				userKey:userkey,
				data:{
					usercode:usercode
				},
				remark:""					
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var list = res.data;
				var imgContent = "";
				for(var i = 0; i < list.length; i++){
					if(i == 0){
						imgContent += "<div class='students-choice students-choice-select' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' ind='" + i +"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}else{
						imgContent += "<div class='students-choice' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' ind='" + i +"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div  class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}
				}					
				$(".dialog-students-contents").empty();
				$(".dialog-students-contents").append(imgContent);
				$(".students-choice").unbind("click");
				$(".students-choice").click(function(){
					$(".students-choice").removeClass("students-choice-select");
					$(this).addClass("students-choice-select");
					
				});
			}else{
				$(".dialog-students-contents").empty();
				$(".dialog-students-contents").append("<div class='students-choice students-choice-select'>没有相关信息</div>");
			}
			changePage(PageUrl.tcourselistUrl);
		},null,null);
	}	
	function pagebtns(){
		$(".left-menu").click(function(){
			$(".left-menu-sec").hide();
			if($(this).attr("model") == "课程表"){
				$("#pcourselist-op").show();
				var Hei = $("#pcourselist-op .menu-sec").length * $(".menu-sec").height();
				$("#pcourselist-op").height(Hei);		
			}else if($(this).attr("model") == "考试"){
				$("#examinfo-op").show();
				var Hei = $("#examinfo-op .menu-sec").length * $(".menu-sec").height();
				$("#examinfo-op").height(Hei);
			}else if($(this).attr("model") == "学生"){
				$("#studentinfo-op").show();
				var Hei = $("#studentinfo-op .menu-sec").length * $(".menu-sec").height();
				$("#studentinfo-op").height(Hei);
			}else if($(this).attr("model") == "考勤"){
				$("#pattence-op").show();
				var Hei = $("#pattence-op .menu-sec").length * $(".menu-sec").height();
				$("#pattence-op").height(Hei);
			}else if($(this).attr("model") == "请假"){
				$("#pleave-op").show();
				var Hei = $("#pleave-op .menu-sec").length * $(".menu-sec").height();
				$("#pleave-op").height(Hei);
			}else if($(this).attr("model") == "通讯录"){
				$("#pmaillist-op").show();
				var Hei = $("#pmaillist-op .menu-sec").length * $(".menu-sec").height();
				$("#pmaillist-op").height(Hei);		
			}
		});
		$(".menu-sec").click(function(){
			var model = $(this).attr("title");
			$(".menu-sec").removeClass("menu-sec-select");
			$(this).addClass("menu-sec-select");
			if(model == "查看课程表"){
				changePage(PageUrl.tcourselistUrl);		
			}else if(model == "考试列表"){
				changePage(PageUrl.pexamUrl);
			}else if(model == "班级小测"){
				changePage(PageUrl.ptestUrl);
			}else if(model == "学生信息"){
				changePage(PageUrl.studentinfoUrl);
			}else if(model == "查看考勤"){
				changePage(PageUrl.pattenceUrl);
			}else if(model == "进校离校"){
				changePage(PageUrl.pinoutSchoolUrl);
			}else if(model == "请假记录"){
				changePage(PageUrl.pleaveUrl);
			}else if(model == "请假申请"){
				changePage(PageUrl.askForLeaveUrl);
			}else if(model == "老师通讯录"){
				changePage(PageUrl.teacherMaillistUrl);
			}
		});
		$(".dialog-display-btnshow").click(function(){
			$(".dialog-display-btnshow").hide();
			$(".dialog-display-btnhide").show();
			$(".student-choice-classdia").animate({right:"0px"});
		});
		$(".dialog-display-btnhide").click(function(){
			$(".dialog-display-btnshow").show();
			$(".dialog-display-btnhide").hide();
			$(".student-choice-classdia").animate({right:"-120px"});
		});
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function changePage(pageUrl){
		$("#right-iframe").attr("src",pageUrl);
	}
	function initSmPages(){
		var bodyRW = $(".index-body",parent.document).width() - $(".body-left").width()-6;
		$(".body-right").width(bodyRW);
		
		var leftCH = $(".body-left").height() - $(".left-title").height()-1;
		$(".left-content").height(leftCH);
	}
	
})();